﻿using System.Globalization;

namespace Koala.Pro.Common.Extension
{

    public static class HexHelper
    {
        public static string ToHexString(uint number)
        {
            string text = $"{number:X}";
            if (text.Length % 2 != 0)
            {
                text = $"0{text}";
            }
            return text;
        }

        public static string ToHexString(ushort number)
        {
            string text = $"{number:X}";
            if (text.Length % 2 != 0)
            {
                text = $"0{text}";
            }
            return text;
        }

        public static string ToHexString(ulong number)
        {
            string text = $"{number:X}";
            if (text.Length % 2 != 0)
            {
                text = $"0{text}";
            }
            return text;
        }

        public static uint ToUInt(string hexString)
        {
            return uint.Parse(hexString, NumberStyles.AllowHexSpecifier);
        }

        public static ulong ToULong(string hexString)
        {
            return ulong.Parse(hexString, NumberStyles.AllowHexSpecifier);
        }

        public static ushort ToUShort(string hexString)
        {
            return ushort.Parse(hexString, NumberStyles.AllowHexSpecifier);
        }
    }
}
